How does one insert a "new line" command in powershell sourcecode


The code below is designed so that my local machine will kill a specific process remotely via powershell...Well i just renamed ALL the machines on my domain and would like to optimize all the scripts i have created. I would like to have the code for each machine as follows: 

  • start powershell{ $remote = new-pssession -computername CPU-180 import-pssession -session $remote -commandname *-process -prefix remote get-remoteprocess -name fwt | stop-remoteprocess -force;}

However that method, the code does not execute correctly. It does not throw an error but it doesnt do what it is supposed to do. This way it will work just fine:

  • start powershell{ $remote = new-pssession -computername CPU-180
  • import-pssession -session $remote -commandname *-process -prefix remote
  • get-remoteprocess -name fwt | stop-remoteprocess -force;}

Now, is there a command or some sort of trigger that i can use to signify in the source code a new line so i dont have such a long script ?

PS: Im working on creating a script that employs a while loop but for now i need this figured out.

October 22nd, 2013 2:44pm

Hi,

You can use the backtick (`) as a line continuation marker:

http://technet.microsoft.com/en-us/library/hh847755.aspx

Free Windows Admin Tool Kit Click here and download it now
October 22nd, 2013 2:53pm

I tried that already, and unfortunately it did not work, see below how i attempted it:
  • start powershell{ $remote = new-pssession -computername CPU-180 ` import-pssession -session $remote -commandname *-process -prefix remote ` get-remoteprocess -name fwt | stop-remoteprocess -force}
This continuation marker is for code that has empty lines in between, my case is the exact opposite, i want to eliminate the line spaces in between to have all the code on ONE line.
October 22nd, 2013 2:59pm

I think I see your problem.

You need to separate commands, not break a single command across lines. Use a semicolon between distinct commands to break them apart.

EDIT: Why are you using start powershell

Free Windows Admin Tool Kit Click here and download it now
October 22nd, 2013 3:07pm

Doh...stupid me, cant believe i forgot all about that. 

Thanks

Im using start powershell { } because its not only one machine im running that line of code on, its 68 machines, so if i dont put that, the code doesnt execute correctly.
October 22nd, 2013 3:53pm

Cheers, very glad it worked out.
Free Windows Admin Tool Kit Click here and download it now
October 22nd, 2013 3:59pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics